/* 
 * File:   SourceReader.h
 * Author: k0l0b0k
 *
 * Created on 8 Октябрь 2009 г., 13:26
 */

#ifndef _SOURCEREADER_H
#define	_SOURCEREADER_H

#include <QString>
#include <QList>
#include "EModifiers.h"
#include "../Error.h"

namespace EEReaderState
{
	enum Enum
	{
		Space,
		Word,
		Operator,
		Char,
		String,
		Comment,
		Directive,
	};
}
typedef EEReaderState::Enum EReaderState;

class SourceReader;

struct Token
{
	QString Text;
	qint32 Line;
	qint32 Col;
	Token* Next;
	Token* Prev;
	SourceReader* Reader;
	bool ContainDots;
};

class Project;

class SourceReader
{
public:
	EModifiers Modifiers;

public:
	SourceReader(QString pFileName, Project* pProject);
	virtual ~SourceReader();

	void Open();
	const QString FileName;
	qint32 Line() { return mCurrentToken ? mCurrentToken->Line : mLine; }
	qint32 Col() { return mCurrentToken ? mCurrentToken->Col : mCol; }

	Token* NextToken();
	Token* CurrentToken();
	bool IsSeparator(QString pSeparators = ";");
	void AddModifier(Token* pToken, EModifiers pModifiersMask);

private:
	QString mSource;
	QList<Token*> mTokens;
	Project* mProject;
	Token* mCurrentToken;

	qint32 mCol;
	qint32 mLine;
	qint32 mIndex;
	Token* mBuildToken;
	EReaderState mState;

private:
	void CheckModifier(Token* pToken, EModifiers pModifier, EModifiers pModifiersMask);
	void ParseSourceFile();
	void ParseSpace();
	void ParseWord();
	void ParseOperator();
	void ParseDirective();
	void ParseChar();
	void ParseString();
	void ParseComment();
	void ParseIfDef();
};

#endif	/* _SOURCEREADER_H */

